#include <bits/stdc++.h>

using namespace std;

class Solution {
   public:
    vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {
        vector<int> ret;
        sort(potions.begin(), potions.end());
        for (int spell : spells) {
            int l = 0, r = potions.size() - 1;
            while (l < r) {
                int mid = l + r >> 1;
                if ((long long)potions[mid] * spell >= success) {
                    r = mid;
                } else {
                    l = mid + 1;
                }
            }
            if (l == potions.size() - 1) {
                if ((long long)spell * potions[l] >= success) {
                    ret.push_back(1);
                } else {
                    ret.push_back(0);
                }
            } else {
                ret.push_back(potions.size() - l);
            }
        }
        return ret;
    }
};